import http from '@/http/index';
import type { Result } from '@/http/type';
import type { DeviceGoods, DeviceGoodsQuery } from '@/types/deviceGoods';

const api = {
  list: '/api/device-goods/page',
  detail: '/api/device-goods',
  add: '/api/device-goods',
  update: '/api/device-goods',
  delete: '/api/device-goods',
  findDetail: '/api/device-goods/find-detail',
};

/**
 * 分页查询货物设置
 * @param params 查询参数
 */
export function getDeviceGoodsList(params: DeviceGoodsQuery) {
  return http.get<Result<any>>(api.list, params);
}

/**
 * 获取货物设置详情
 * @param id 货物设置ID
 */
export function getDeviceGoodsDetail(id: number | string) {
  return http.get<Result<DeviceGoods>>(`${api.detail}/${id}`);
}

/**
 * 新增货物设置
 * @param data 货物设置数据
 */
export function addDeviceGoods(data: DeviceGoods) {
  return http.post<Result<boolean>>(api.add, data);
}

/**
 * 更新货物设置
 * @param data 货物设置数据
 */
export function updateDeviceGoods(data: DeviceGoods) {
  return http.put<Result<boolean>>(api.update, data);
}

/**
 * 删除货物设置
 * @param id 货物设置ID
 */
export function deleteDeviceGoods(id: number | string) {
  return http.delete<Result<boolean>>(`${api.delete}/${id}`);
}

/**
 * 根据条件查询货物设置详情
 * @param data 查询条件
 */
export function findDeviceGoodsDetail(data: {
  name?: string;
  weight?: number;
  length?: number;
  specifications?: string;
}) {
  return http.post<Result<DeviceGoods>>(api.findDetail, data);
} 